package com.yanqu.road.server.cmd.activity.zhenhuan.secondProcess.cross;

import com.yanqu.road.dao.impl.player.UserZhenHuanKickDaoImpl;
import com.yanqu.road.entity.activity.zhenhuan.secondProcess.UserZhenHuanKickData;
import com.yanqu.road.logic.activity.zhenhuan.ZhenHuanSecondProcessConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.zhenhuan.ZhenHuanSecondProcessModule;
import com.yanqu.road.server.manger.activity.zhenhuan.ZhenHuanConfigMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_ZHENHUAN_SECOND_PROCESS_NEW_KICK_RECORD_CROSS_BACK, desc = "甄嬛第二阶段茶话会新的踢人记录")
public class ZhenHuanSecondProcessNewKickRecordFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ZhenHuanProto.CrossZhenHuanSecondProcessNewKickRecordRespMsg respMsg = ZhenHuanProto.CrossZhenHuanSecondProcessNewKickRecordRespMsg.parseFrom(packet.getBytes());
        long beKickUserId = respMsg.getBeKickUserId();

        ZhenHuanSecondProcessConfig secondProcessConfig = ZhenHuanConfigMgr.getSecondProcessConfig();
        if (secondProcessConfig == null) {
            log.error("ZhenHuanSecondProcessNewKickRecordFromCrossCmd execute error, secondProcessConfig is null, beKickUserId = {}", beKickUserId);
            return;
        }
//        public UserZhenHuanKickData(int activityId, long userId, long partyId, long kickTime, long kickUserId, int attackLevel, long attackPrestige, int defendLevel, long defendPrestige) {
//            this.activityId = activityId;
//            this.userId = userId;
//            this.partyId = partyId;
//            this.kickTime = kickTime;
//            this.kickUserId = kickUserId;
//            this.attackLevel = attackLevel;
//            this.attackPrestige = attackPrestige;
//            this.defendLevel = defendLevel;
//            this.defendPrestige = defendPrestige;
//        }

        UserZhenHuanKickData kickData = new UserZhenHuanKickData(respMsg.getActivityId(), beKickUserId, respMsg.getPartyId(), respMsg.getKickTime(),
                respMsg.getKickUserId(), respMsg.getAttackLevel(), respMsg.getAttackPrestige(), respMsg.getDefendLevel(),
                respMsg.getDefendPrestige(),respMsg.getPos(),respMsg.getOpenUserId(), respMsg.getOpenUserName(), respMsg.getPartyLevel());

        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(beKickUserId);
        if (onlinePlayer != null) {
            onlinePlayer.getModule(ZhenHuanSecondProcessModule.class).addNewKickRecord(kickData);
        } else {
            //离线玩家直接入库
            new UserZhenHuanKickDaoImpl().add(kickData);
        }

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
